<?php
	/* Required Objects */
	require_once ('../businessObjects/userAccount.php');	
	/* Script Variables */	
	$user = new userAccount();
	$message = '';	
	if ($user->userAccountInformation($_SESSION['username'])){		
		$userInfo = mysqli_fetch_array($user->resultSet(),MYSQLI_ASSOC);		
	}else{
		$message = $user->message();
	}
	if ($_POST['hddfrmUserAccountSeed']==1){
		$user->updateUserPassword($_SESSION['username'],$_POST['txtOldPassword'],$_POST['txtNewPassword1']);
		$message = $user->message();
	}
?>
<script language="javascript" type="text/javascript">
	$(document).ready(function(){
	   	$('#frmUserAccount').validate({
			rules:{
				txtOldPassword: {required:true},
				txtNewPassword1: {required:true},
				txtNewPassword2: {required:true, equalTo:'#txtNewPassword1'}
				},
			messages:{
				txtOldPassword: {required:"*"},
				txtNewPassword1: {required:"*"},
				txtNewPassword2: {required:"*",equalTo:'Must be equal to new password'}
			}
		});
	});    
</script>
<form id="frmUserAccount" action="?action=USERACCOUNTUPDATE" method="post" enctype="application/x-www-form-urlencoded">
<?php include ('message.php'); ?>
<h1> Account Settings </h1>
<h2> Employee Information </h2>
	<div class="frmContainer" style="width:50%">
    	<div class="frmRow">
        	<div class="frmLabelCell">Dependency</div>
            <div class="frmContentCell"><?=$userInfo['enterpriseName']?></div>
        </div>
		<div class="frmRow">
        	<div class="frmLabelCell">Name</div>
            <div class="frmContentCell"><?=$userInfo['lastName'].' , '.$userInfo['firstName']?></div>
        </div>
    </div>
<h2> Account Information </h2>
	<div class="frmContainer" style="width:50%">
    	<div class="frmRow">
        	<div class="frmLabelCell">Username</div>
            <div class="frmContentCell"><?=$userInfo['username']?></div>
        </div>
		<div class="frmRow">
        	<div class="frmLabelCell">Old Password</div>
            <div class="frmContentCell"><input type="password" id="txtOldPassword" name="txtOldPassword" class="controlTextBox" /></div>
        </div>
        <div class="frmRow">
        	<div class="frmLabelCell">New Password</div>
            <div class="frmContentCell"><input type="password" id="txtNewPassword1" name="txtNewPassword1" class="controlTextBox" /></div>
        </div>
        <div class="frmRow">
        	<div class="frmLabelCell">Confirm Password</div>
            <div class="frmContentCell"><input type="password" id="txtNewPassword2" name="txtNewPassword2" class="controlTextBox" /></div>
        </div>
        <div class="frmRow">
        	<div class="frmLabelCell"><br /></div>
            <div class="frmContentCell"><input type="submit" id="bntSubmit" name="bntSubmit" class="controlSubmit" value="Update" /></div>
			<input type="hidden" id="hddfrmUserAccountSeed" name = "hddfrmUserAccountSeed" value="1" />
        </div>
    </div>
</form>